package app.esb.tags;

import app.common.dao.Leo_tagBean;
import app.common.dao.Leo_tag_relaBean;
import app.esb.BaseExcutor;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.container.reader.DataTable;
import cn.lily.com.lang.Basic;
import cn.lily.com.lang.BusinessDate;
/**
 * 标签处理类
 * @author JiaJ
 * @date 2017年12月2日
 *
 */
public class TagExcutor extends BaseExcutor {
	
	/**
	 * 插入类型
	 * @param type
	 * @param canDetailID
	 */
	public static void insertTags(String tags,String resID ){	
	
		 if(tags != null && !"".equals(tags)){
			 
			 String[] firm = Basic.split(tags, ",","，");
			 
			 for(String active:firm){
				 
				 active = active.trim();
				 
				 Leo_tag_relaBean relaBean = new Leo_tag_relaBean();
				 Leo_tagBean tagBean = new Leo_tagBean();
				 
				 DataTable dt = DBFactory.getActionDB().executeQueryTable("select * from ${schema}.LEO_TAG where TAG_NAM='"+active+"'");
				 
				 int size = dt.getRecordCount();
				 
				 if(size == 0){
					 
					 String tagID = getDBSequence().getBussSeq("leo_tag_id", 8);
					 tagBean.setTag_id(tagID);
					 tagBean.setTag_nam(active);
					 tagBean.setCreate_oper("9999");
					 tagBean.setCreate_time(BusinessDate.getTodaytime());
					 tagBean.insert();
					 
					 relaBean.setRes_id(resID);
					 relaBean.setTag_id(tagID);
					 relaBean.insert();
					 
				 }else{
					 
					 dt.next();
					 
					 relaBean.setTag_id(dt.getString("TAG_ID"));
					 relaBean.setRes_id(resID);
					 relaBean.insert();
					 
				 }
				 
				 
			}
			
		 }
	
	 }
	
	/**
	 * 删除类型信息
	 * @param canDetailID
	 */
	public static void delTags(String resID){
		String sql = "delete from ${schema}.LEO_TAG_RELA where RES_ID='"+resID+"'";
		DBFactory.getActionDB().executeUpdate(sql);
	}
	
	public static String getTags(String canID){
		String sql = "select lr.* "
				   + "from ${schema}.LEO_RES_INFO lr "
				   + "inner join ${schema}.LEO_CAN_DETAIL_INFO lc on lr.RES_ID=lc.RES_ID "
				   + "where lc.CAN_ID='"+canID+"'";
		DataTable dt = DBFactory.getActionDB().executeQueryTable(sql);
		
		if(dt.next()){
			return dt.getString("RES_TAG_MEMO");
		}else{
			return "";
		}		
	}
	
	public static String getHCNTags(String canID){
		String sql = "select lr.* "
				   + "from ${schema}.LEO_RES_INFO lr "
				   + "inner join ${schema}.LEO_GALCAN_DETAIL_INFO lc on lr.RES_ID=lc.RES_ID "
				   + "where lc.CAN_ID='"+canID+"'";
		DataTable dt = DBFactory.getActionDB().executeQueryTable(sql);
		
		if(dt.next()){
			return dt.getString("RES_TAG_MEMO");
		}else{
			return "";
		}		
	}
	
}
